'use strict';

var Model = require('../../config/models').menuModel;
var service = module.exports = {};

service.create = function(model) {
  return Model.create(model);
};

service.find = function(conditions, projection, options) {
  return Model.find(conditions, projection, options).exec();
};

service.remove = function(conditions) {
  return Model.remove(conditions);
};

service.update = function(conditions, update) {
  return Model.update(conditions, update).exec();
};

service.findById = function(id) {
  return Model.findById(id).exec();
};

service.findOne = function(conditions) {
  return Model.findOne(conditions).exec();
};

service.findByIdAndUpdate = function(id, update, options) {
  return Model.findByIdAndUpdate(id, update, options).exec();
};

service.findByIdAndRemove = function(id, options) {
  return Model.findByIdAndRemove(id, options).exec();
};

service.findOperatorsByMenuId = function(id) {

};

/*service.createOperatorByMenuId = function(id, entity) {
  // make sure operatorList has not an item name is entity name.
  // return this.update({_id: id, operatorList.name: {$ne: entity.name}},
  //   {$push: {operatorList: entity}});
  return this.update({_id: id}, {$addToSet: {operatorList: entity}});
};

service.updateOperatorByMenuId = function(id, entity) {
  return this.update({_id: id, operatorList.name: entity.name},
    {operatorList.$: entity});
};

service.removeOperatorsByMenuId = function(id, conditions) {
  return this.update({_id: id, operatorList.name: entity.name},
    {$pull {operatorList: operatorList.$}});
};

service.updateOperatorsByMenuId = function(id, entity) {
  // modify all operatorList
  return this.update({_id: id},
    {$set: {operatorList: entity}});
};*/
